<!DOCTYPE html>
<html>
<head>
    <title>枣阳市第二人民医院管理系统--中软高科2015</title>
	<meta charset="UTF-8">
   <link rel="stylesheet" type="text/css" href="Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="Css/style.css" />
    <script type="text/javascript" src="Js/jquery.js"></script>
<!--    <script type="text/javascript" src="Js/jquery.sorted.js"></script>-->
    <script type="text/javascript" src="Js/bootstrap.js"></script>
    <script type="text/javascript" src="Js/ckform.js"></script>
    <script type="text/javascript" src="Js/common.js"></script>
    <script src="/layer/layer.js"></script>
    <style type="text/css">
        body {
            padding-top: 40px;
            padding-bottom: 40px;
            background-color: #f5f5f5;
        }

        .form-signin {
            max-width: 300px;
            padding: 19px 29px 29px;
            margin: 0 auto 20px;
            background-color: #fff;
            border: 1px solid #e5e5e5;
            -webkit-border-radius: 5px;
            -moz-border-radius: 5px;
            border-radius: 5px;
            -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
            -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
            box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
        }

        .form-signin .form-signin-heading,
        .form-signin .checkbox {
            margin-bottom: 10px;
        }

        .form-signin input[type="text"],
        .form-signin input[type="password"] {
            font-size: 16px;
            height: auto;
            margin-bottom: 15px;
            padding: 7px 9px;
        }

    </style>  
</head>
<body>
<div class="container">

    <form class="form-signin" method="post" action="index.html#1/2" id="myForm">
        <h2 class="form-signin-heading">&nbsp;&nbsp;&nbsp;登录系统</h2>
        <input style="margin-bottom: 5px" type="text" id="userName" name="userName" class="input-block-level" placeholder="账号">
        <span  id="usernameMsg"  style="line-height: 15px;height: 15px;display: block" ></span>
        <input style="margin-bottom: 5px;margin-top: 15px" type="password" id="password" name="password" class="input-block-level" placeholder="密码">
        <span  style="line-height: 15px;height: 15px;display: block;" id="passwordMsg"></span>
            <a href="javascript:void(0);" title="点击更换验证码">
                <img style="display: block;margin-top: 15px"  id="imgVerify" src="/admin/createImg" title="更换验证码" height="36" width="150" onclick="getVerify(this);"/>
            </a>


        <input type="text"  name="verifyCode" class="input-small" placeholder="验证码" >
        <span style="font-size: 13px" id="spanTip"></span>

       
        <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-large btn-primary" type="button" id="login">登录</button></p>
    </form>

</div>
</body>
</html>
<script>
    $(function () {
       // var nameFlag;
        //var passwordFlag;
        $("#userName").blur(function () {
            validateName();
        });
        $("#password").blur(function () {
             validatePassword();
        });

        $("#login").click(function () {
            if(validateName()&&validatePassword()&&validatePassword()){
                if(verifyCodeNotNull()){
                    $.ajax({
                        type: "POST",
                        url: "/admin/login", //RESTful风格的API定义
                        data: $("#myForm").serialize(),
                        dataType:"JSON",
                        success: function (vo) {
                            if(vo.code==200){
                                window.location.href="/index.html";
                            }else{
                                layer.msg(vo.msg);
                            }
                        }
                    });
                }
            }
        });
    });
    function getVerify(obj){
        let num=Math.round(10*Math.random());
        obj.src = "/admin/createImg?"+num;
    }
    /*function verifyCode() {
        if(verifyCodeNotNull()){
            let verifyCode = $("input[name='verifyCode']").val();
            let codeMsg = $("#spanTip");
            $.post("/user/verifyCode", "verifyCode=" + verifyCode, function (vo) {
                if (vo.code == 200) {
                    codeMsg.html(vo.msg).css("color", "green");
                    return true;
                } else {
                    codeMsg.html(vo.msg).css("color", "red");
                    return false;
                }
            }, "JSON");
        }
    }*/
    function verifyCodeNotNull() {
        let verifyCode = $("input[name='verifyCode']").val();
        let reg = /^[A-Z0-9]{4}$/;
        let codeMsg = $("#spanTip");
        if(verifyCode == null || verifyCode == "") {
            codeMsg.html("验证码不能为空").css("color", "red");
            return false;
        }else if(!reg.test(verifyCode)){
            codeMsg.html("请正确填写验证码").css("color", "red");
            return false;
        }
        codeMsg.html("");
        return true;
    }
    function validateName() {
        var reg = /^[a-zA-Z0-9]{4,20}$/;
        //var reg1 = /^[0-9]{4,20}$/;
        var name = $("#userName").val();
        var nameMsg = $("#usernameMsg");
        if(name == null || name == "") {
            nameMsg.html("用户名不能为空").css("color", "red");
            return false;
        } /*else if(reg1.test(name)) {
            nameMsg.html("用户名必须包含字母").css("color", "red");
            return false;
        }*/ else if(!reg.test(name)) {
            nameMsg.html("用户名长度不合法").css("color", "red");
            return false;
        }
        nameMsg.html("用户名合法").css("color", "green");
        return true;
    }

    function validatePassword() {
        var reg = /\w{6,15}$/;
        //var reg1 = /^[0-9]{6,15}$/;
        var password = $("#password").val();
        var passwordMsg = $("#passwordMsg");
        if(password == null || password == "") {
            passwordMsg.html("密码不能为空").css("color", "red");
            return false;
        } /*else if(reg1.test(password)) {
            passwordMsg.html("密码必须包含字母").css("color", "red");
            return false;
        } */else if(!reg.test(password)) {
            passwordMsg.html("密码至少六位").css("color", "red");
            return false;
        }
        passwordMsg.html("密码填写合法").css("color", "green");
        return true;
    }
</script>